package com.scau.dao.Impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.scau.dao.VideoDao;
import com.scau.mapper.VideoMapper;
import com.scau.pojo.Student;
import com.scau.pojo.Video;
import com.scau.util.SqlSessionFactoryUtil;
@Repository
public class VideoDaoImpl implements VideoDao{
	
	SqlSession session = SqlSessionFactoryUtil.getSession();
	VideoMapper videoMapper=session.getMapper(VideoMapper.class);
	
	@Override
	public List<Video> query(int id) {
		return videoMapper.selectBySectionId(id);
	}

	@Override
	public int countBySeId(int id) {
		return videoMapper.countByExample(id);
	}


	public int add(Video video) {
		return videoMapper.insertSelective(video);
	}

	public int update(Video video) {
		return videoMapper.updateByPrimaryKeySelective(video);
	}

	@Override
	public int delete(int id) {
		return videoMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int isNameExist(String vName,Integer seId) {
		int result=-1;
		Video video1=new Video();
		Video video=new Video();
		video1.setSeId(seId);
		video1.setvName(vName);
		try {
			video=videoMapper.selectByName(video1);
			if(video!=null){
				result=1;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	
	@Override
	public int isSeqExist(Integer vSeq,Integer seId) {
		int result=-1;
		Video videoReturn=new Video();
		Video video=new Video();
		video.setSeId(seId);
		video.setvSeq(vSeq);
		try {
			videoReturn=videoMapper.selectBySeq(video);
			if(videoReturn!=null){
				result=1;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
}
